package com.supereye.platform.web.expert.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.supereye.platform.base.BaseDao;
import com.supereye.platform.interfaces.BzClient;
import com.supereye.platform.web.expert.model.TopExpert;

@Repository
public class ExpertDao extends BaseDao {

	public void addExpert(TopExpert expert) throws Exception {
		sqlSessionTemplate.insert("com.supereye.platform.web.expert.dao.ExpertDao.addTopExpert", expert);
	}

	public List<TopExpert> getExpertList(Map<String,Object> params) throws Exception {
		return sqlSessionTemplate.selectList("com.supereye.platform.web.expert.dao.ExpertDao.queryExpert", params);
	}

	public void deleteExperts(String[] expertIds) throws Exception {
		List<Object[]> params = new ArrayList<Object[]>();
		for(String expertId:expertIds){
			params.add(new String[]{expertId});
			
			BzClient.getClient().delUser(Integer.parseInt(expertId));
		}
		jdbcTemplate.batchUpdate("delete from top_expert where id=?", params);
	}

	public void updateExpert(TopExpert expert) throws Exception {
		sqlSessionTemplate.update("com.supereye.platform.web.expert.dao.ExpertDao.updateTopExpert", expert);
	}

	public int getExpertNumByAccount(String account) throws Exception {
		return jdbcTemplate.queryForObject("select count(*) from top_expert where account=?", new Object[]{account}, Integer.class);
	}

	public void updateRelateId(TopExpert expert) throws Exception {
		sqlSessionTemplate.insert("com.supereye.platform.web.expert.dao.ExpertDao.updateRelateId", expert);
	}

	public Integer getExpertListCount(Map<String, Object> params) throws Exception {
		return sqlSessionTemplate.selectOne("com.supereye.platform.web.expert.dao.ExpertDao.queryExpertCount", params);
	}

}
